# coding=gb18030
from xml.dom.minidom import Document
import pysvn
import argparse
import os
import subprocess
import shutil

TEST_TOOLS_PATH = 'moon-test/TestTools'
CHECK_TABLE_LIB = 'svn://xsjreposvr2/QCBase/trunk/SourceCode/Common/CheckTable'
TEST_CASE = 'svn://xsjreposvr2/QCBase/trunk/SourceCode/Test/moon/TestTable'
LUA_PATH = 'svn://xsjreposvr2/QCBase/trunk/Product/3rdparty/Application/lua'


RES_PATH = '\\\\10.20.79.150\\Share\\baiyinzu\\Res_Files'


def GetLogin(self, realm, user, may_save):
        return True, 'xsjqc_dev', 'asp@xsj', False

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--case_param')
    
    args = parser.parse_known_args()
    svn  = pysvn.Client()
    svn.callback_get_login = GetLogin
    
    
    os.makedirs(TEST_TOOLS_PATH)
    os.makedirs(TEST_TOOLS_PATH)
    
    svn.checkout(CHECK_TABLE_LIB, TEST_TOOLS_PATH)
    svn.checkout(TEST_CASE, TEST_TOOLS_PATH)
    svn.checkout(LUA_PATH, './')
    
    shutil.copy(RES_PATH, 'Res_File')
    
    checktableconfig = open('TestCaseConfig.xml', 'w')
    
    doc.writexml(checktableconfig,  addindent="\t", newl="\n")
    
    
    svn  = pysvn.Client()
    svn.callback_get_login = GetLogin
    
    svn.checkout("svn://xsjreposvr2/QCBase/trunk/Product/Platform/CheckTableRunner", './')
    
    svn.checkout(args.casesvnpath, 'cases')
    
    for v in args.ressvnpath.split(":"):
        svn.checkout(v, 'Res_File')
    
    p = subprocess.Popen('CheckTableRunner.exe')
    p.wait()
    
    
    

print('ok')